package cn.gyouzhe.service.impl;

import cn.gyouzhe.entity.Coupon;
import cn.gyouzhe.mapper.CouponMapper;
import cn.gyouzhe.service.ICouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 券service
 *
 * @author wangchuan
 * @datetime 2018/3/3 16:14
 */
@Service
@Transactional(readOnly = true)
public class CouponService implements ICouponService {
    @Autowired
    private CouponMapper couponMapper;
    /**
     * 查询券信息
     * @param couponId 券ID
     * @return 券信息
     */
    @Override
    public Coupon selectCoupon(String couponId) {
        return couponMapper.selectCoupon(couponId);
    }

    /**
     * 保存券信息
     * @param coupon 券信息
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
    @Override
    public void saveCoupon(Coupon coupon) {
        couponMapper.saveCoupon(coupon);
    }

    /**
     * 删除券信息
     * @param id 券数据库ID
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
    @Override
    public void deleteCoupon(int id) {
        couponMapper.deleteCoupon(id);
    }

    /**
     * 查询过期券
     * @param expireTime 过期时间
     * @return 券列表
     */
    @Override
    public List<Coupon> selectExpireCoupon(LocalDateTime expireTime) {
        return couponMapper.selectExpireCoupon(expireTime);
    }
}
